package com.whc.search.controller;

import com.whc.search.service.MallSearchService;
import com.whc.search.vo.SearchParam;
import com.whc.search.vo.SearchResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author angaoen
 */
@Controller
public class SearchController {


    @Resource
    private MallSearchService mallSearchService;

    /**
     * 根据条件查询
     *
     * @param searchParam 查询参数
     * @param model       定义模型属性持有者的 Java-5 特定接口。
     * @param request     扩展ServletRequest接口以提供 HTTP servlet 的请求信息。
     * @return 返回结果
     */
    @GetMapping({"/", "/list.html"})
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request) {
        // _queryString是个字段
        searchParam.set_queryString(request.getQueryString());
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }


}
